﻿using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PlanningGIS.Util;

namespace PlanningGIS.Win.Controls
{
    /// <summary>
    /// 控件操作类
    /// </summary>
    public class MsgHelper
    {
        /// <summary>
        /// 对话框要显示在那个窗体上
        /// </summary>
        private static IWin32Window  _owner;

        /// <summary>
        /// 对话框要显示在那个窗体上
        /// </summary>
        public static IWin32Window OWNER
        {
            set { _owner = value; }
        }

        /// <summary>
        /// 静态构造函数
        /// </summary>
        static MsgHelper()
        {
            MessageBoxEx.DefaultStartPosition = FormStartPosition.CenterScreen;
            MessageBoxEx.EnableGlass = false;
        }

        #region 弹出窗口
        /// <summary>
        /// 消息委托
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        private delegate void MsgDelegate(Form owner, string msg);

        /// <summary>
        /// 提示窗口
        /// </summary>
        /// <param name="msg"></param>
        public static void ShowInfomationMsgbox(string msg)
        {
            ShowInfomationMsgbox(_owner as Form, msg);
        }

        /// <summary>
        /// 提示窗口
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        public static void ShowInfomationMsgbox(Form owner, string msg)
        {
            if (owner != null && owner.InvokeRequired)
            {
                MsgDelegate invoke = new MsgDelegate(ShowInfomationMsgbox);
                owner.Invoke(invoke, owner, msg);
            }
            else
            {
                MessageBoxEx.Show(owner, msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, true);
            }
        }

        /// <summary>
        /// 桌面提示窗口
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        public static void ShowInfomationAlert(Form owner, string msg)
        {
            if (owner != null && owner.InvokeRequired)
            {
                MsgDelegate invoke = new MsgDelegate(ShowInfomationAlert);
                owner.Invoke(invoke, owner, msg);
            }
            else
            {
                DesktopAlert.Show(string.Format("<b>{0}</b>", msg));
            }
        }

        /// <summary>
        /// 桌面提示窗口
        /// </summary>
        /// <param name="msg"></param>
        public static void ShowInfomationAlert(string msg)
        {
            ShowInfomationAlert(_owner as Form, msg);
        }

        /// <summary>
        /// 警告窗口
        /// </summary>
        /// <param name="msg"></param>
        public static void ShowWarningMsgbox(string msg)
        {
            ShowWarningMsgbox(_owner as Form, msg);
        }

        /// <summary>
        /// 警告窗口
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        public static void ShowWarningMsgbox(Form owner, string msg)
        {
            if (owner != null && owner.InvokeRequired)
            {
                MsgDelegate invoke = new MsgDelegate(ShowWarningMsgbox);
                owner.Invoke(invoke, owner, msg);
            }
            else
            {
                MessageBoxEx.Show(owner, msg, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, true);
            }
        }

        /// <summary>
        /// 错误窗口
        /// </summary>
        /// <param name="msg"></param>
        public static void ShowErrorMsgbox(string msg)
        {
            ShowErrorMsgbox(_owner as Form, msg);
        }

        /// <summary>
        /// 错误窗口
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        public static void ShowErrorMsgbox(Form owner, string msg)
        {
            if (owner != null && owner.InvokeRequired)
            {
                MsgDelegate invoke = new MsgDelegate(ShowErrorMsgbox);
                owner.Invoke(invoke, owner, msg);
            }
            else
            {
                MessageBoxEx.Show(owner, msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, true);
            }
        }

        /// <summary>
        /// 询问窗口，“是”、“否”两种种状态
        /// </summary>
        /// <param name="question"></param>
        /// <param name="owner"></param>
        /// <returns></returns>
        public static DialogResult ShowYesOrNoQueryMsgBox(string question, Form owner = null)
        {

            return MessageBoxEx.Show(owner, question, "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, true);
        }

        /// <summary>
        /// 询问窗口，“是”、“否”、“取消”三种状态
        /// </summary>
        /// <param name="question"></param>
        /// <param name="owner"></param>
        /// <returns></returns>
        public static DialogResult ShowYesNoCancelQueryMsgbox(string question, Form owner = null)
        {
            return MessageBoxEx.Show(owner, question, "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, true);
        }
        #endregion
    }
}
